#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>

void Worker()
{
    int cnt = 5;
    while(cnt)
    {
        printf("i am child, pid: %d, ppid: %d, cnt: %d\n", getpid(), getppid(), cnt--);
        sleep(1);
    }
}

int main()
{
    pid_t id = fork();

    if(id == 0)
    {
        // child
        Worker();
        exit(0);
    }
    else{
        sleep(10);
        // father
        pid_t rid = wait(NULL);
        if(rid == id)
        {
            printf("wait success, pid: %d\n", getpid());
        }
    }

    return 0;
}
